package org.dexter.model
{
	import flash.display.Loader;
	import flash.events.Event;
	import flash.net.URLRequest;
	import flash.system.ApplicationDomain;
	import flash.system.LoaderContext;

	public class BadgerModel
	{
		public var appURL: String;
		public var airVersion: String;
		
		private var _loader:Loader;
		private var _air:Object;
		[Bindable]
		public var initialized:Boolean;
		public function BadgerModel()
		{
			_loader = new Loader();
			_loader.contentLoaderInfo.addEventListener(Event.INIT, onInit);
			_loader.load(new URLRequest("http://airdownload.adobe.com/air/browserapi/air.swf"), new LoaderContext(false,ApplicationDomain.currentDomain));
		}
		private function onInit(e:Event):void {
			_air = e.target.content;
//			switch (_air.getStatus(airVersion)) {
//				case "installed" :
//					break;
//				case "available" :
//					if (_appName && _appName.length > 0) {
////						root.statusMessage.htmlText = "<p align='center'><font color='#" + _messageColor + "'>In order to run " + _appName + ", this installer will also set up Adobe® AIR®.</font></p>";
//					} else {
////						root.statusMessage.htmlText = "<p align='center'><font color='#" + _messageColor + "'>In order to run this application, this installer will also set up Adobe® AIR®.</font></p>";
//					}
//					break;
//				case "unavailable" :
////					root.statusMessage.htmlText = "<p align='center'><font color='#" + _messageColor + "'>Adobe® AIR® is not available for your system.</font></p>";
//					break;
//			}
			initialized = true;
		}
		[DexterEvent]
		public function installAirApp():void{
			if( !initialized ) return;
			try {
				_air.installApplication( appURL, airVersion );
//				switch (_air.getStatus(airVersion)) {
//					case "installed" :
////						root.statusMessage.htmlText = "<p align='center'><font color='#" + _messageColor + "'>Download and open the AIR file to begin the installation.</font></p>";
//						_air.installApplication( appURL, airVersion );
//						break;
//					case "available" :
////						root.statusMessage.htmlText = "<p align='center'><font color='#" + _messageColor + "'>Starting install...</font></p>";
//						_air.installApplication( appURL, airVersion );
//						break;
//					case "unavailable" :
//						// do nothing
//						break;
//				}
			} catch (e:Error) {
//				root.statusMessage.text = e.message;
			}
		}
	}
}